home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question on char to int and back
  5. Date: 4 Feb 1996 11:17:58 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4f24l6$mno@news1.usa.pipeline.com>
  8. References: <4f1988$dnk@ns.cs.hku.hk>
  9. NNTP-Posting-Host: 38.8.60.5
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete)
  13. X-Newsreader: Pipeline USA v3.3.0
  14.  
  15. On Feb 04, 1996 03:30:16 in article <Re: Question on char to int and back>,
  16. 'kwho@csd.hku.hk (Lord Hermes)' wrote: 
  17.  
  18.  
  19. >: This might seem like a trivial question but I would like to know how I
  20. can  
  21. >go 
  22. >: from reading in a char, placing it in a stack of int (ie) 
  23. >:         char c;  
  24. >:         c = cin.get() 
  25. >:         push(s,c); 
  26. >:         now if the char was a '+', it would be entered into the stack as
  27. 43. 
  28. >:         I know that a cout.put(c) will output it as a character but if I
  29. want  
  30. >:         to pop it from the stack and act on it as a character how do I 
  31. >:         convert it back to a character? 
  32. >    Can it be "a = (char) (c && 0x00ff)"? (a is the character you 
  33. >want; c is the integer you pop from the stack) 
  34.  
  35. A more appropriate answer is that 43 is the internal representation 
  36. of the character '+' (in ASCII, anway).  You can use this value 
  37. directly without conversion (conversion to what?).  Examples: 
  38.  
  39.    if (c == '+') dosomething(); 
  40.  
  41.    switch (c) 
  42.     { 
  43.        case '+': doit(); break; 
  44.        case '-': doopposite(); break; 
  45.        ..... 
  46.  
  47. -- 
  48. Pete Grant 
  49. Kalevi, Inc. 
  50. Object Oriented Software Development
  51.